﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using SeventhSenseSystems.HighFlyingPm.Business.Entities;
using SeventhSenseSystems.HighFlyingPm.Business.Models;

namespace WebBusiness.Controllers
{
    [Export("wiki", typeof(IController))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public class WikiController:Controller
    {
        private readonly IWikiContentRepository wikiContentRepository;


        		[ImportingConstructor]
        public WikiController(IWikiContentRepository wikiContentRepository)
		{
            this.wikiContentRepository = wikiContentRepository;
		}

        public ActionResult Index(string project,string slug, Guid? id  )
        {
            ViewBag.project = project;
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult EditWiki(int id, string slug)
        {
            if (!IsEditable())
                return RedirectToAction("Index");

            WikiContent content = wikiContentRepository.Find(id);

            if (content == null)
                content = new WikiContent { WikiTitle = new WikiTitle() { Slug = slug } };

            return View("EditWiki", content);
        }

        private static bool IsEditable()
        {
            return true;
        }
    }
}
